﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using GosWeb.Biz;
using GosWeb.Models.Db;

namespace GosWeb.Models
{

    public class ExistBiontAttribute : ValidationAttribute
    {
        public override bool IsValid(object AnID)
        {
            string anIdStr = AnID as string;
            //GosDBContext db = GosDBContext.GetInstance();
            BiontBiz abiz = new BiontBiz();
            Biont a=abiz.FindBiont(anIdStr);
            if (a == null)
            {
                ErrorMessage = "Biont 不存在";
                return false;
            }
            else
            {
                return true;
            }
        }
    }

    /// <summary>
    /// for validate BiontNormal 
    /// </summary>
    public class ValidBiontNAttribute : ValidationAttribute
    {
        public override bool IsValid(object AnN)
        {
            Biont anN = AnN as Biont;
            //GosDBContext db = GosDBContext.GetInstance();
            BiontBiz abiz = new BiontBiz();

            if (anN.ValidFatherGender() == false)
            {
                ErrorMessage = "Biont 父性别不对。";
                return false;
            }
            if (anN.ValidMotherGender() == false)
            {
                ErrorMessage = "Biont 母性别不对。";
                return false;
            }

           return true;
        
        }
    }
}